package com.clps.controller;


import com.clps.common.R;
import com.clps.dto.BankcardDto;
import com.clps.entity.Bankcard;
import com.clps.mapper.BankcardMapper;
import com.clps.service.BankcardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ywl
 * @since 2022-09-08
 */
@RestController
@RequestMapping("/bankcard")
@Api(tags = "银行卡相关控制器")
public class BankcardController {

    @Autowired
    BankcardService bankcardService;
    @Autowired
    BankcardMapper bankcardMapper;

    /**
     * 查询当前用户所有的银行卡号
     * @return
     */
    @ApiOperation("查询用户卡号")
    @GetMapping("/carNumberList")
    public R<List<String>> getCarNumberList(){
        List<String> allCardNumber = bankcardMapper.getAllCardNumber();
        return allCardNumber != null ?R.success(allCardNumber):R.error("请求失败");
    }

    /**
     * 根据银行卡号查询相关信息，并进行回显
     */
    @ApiOperation("根据银行卡号查询相关信息，并进行回显")
    @GetMapping("/getByCardNumber")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cardNumber",value = "银行卡号",required = true)
    })
    public R<BankcardDto> getBankCardWithUserInfo(String cardNumber){
        BankcardDto bankcardDto = bankcardMapper.getBankCardWithUserInfo(cardNumber);
        if(bankcardDto == null){
            return R.error("请求失败");
        }
        bankcardDto.setCreateTime(LocalDateTime.now());
        bankcardDto.setStatus("待审批");
        return R.success(bankcardDto);
    }

}

